<!-- Copyright (c) 2022 渝州大数据实验室
 *
 * Lanius is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *
 *     http://license.coscl.org.cn/MulanPSL2
 *
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 -->
<!-- 
* @desc:图片组件
* @fileName:LaniusImage.vue
* @author:zoujunjie@yzbdl.ac.cn
* @date:2022-4-25
* 用法：和常规图片一样，传入src参数，如果src以/开头，则自动从后端API地址获取图片
!-->
<template>
  <el-image :src="displaySrc"></el-image>
</template>

<script lang="ts" setup>
import { computed } from "vue";

const props = withDefaults(defineProps<{ src: string }>(), {
  src: "",
});

const displaySrc = computed(() => {
  if (props.src) {
    let src = props.src.trim();
    if (src.startsWith("/")) {
      return import.meta.env.VITE_API_BASE_URL + src;
    }
    return src;
  }
  return "";
});
</script>
